package com.bazaaroid.server.gae.core.dao.partner.impl;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.bazaaroid.server.gae.core.dao.impl.JDOGenericDAOImpl;
import com.bazaaroid.server.gae.core.dao.partner.TagDAO;
import com.bazaaroid.server.gae.core.persistence.model.partner.Tag;
import com.google.appengine.api.datastore.Key;

public class JDOTagDAOImpl extends JDOGenericDAOImpl<Tag, Key> implements TagDAO {

	public Tag getTagByName(String name) {
		PersistenceManager persistenceManager = getPersistenceManager();
		persistenceManager.setDetachAllOnCommit(true);
		Tag tag = null;

		Query query = persistenceManager.newQuery(getEntityClass());
		query.setFilter("name == nameParam");
		query.declareParameters("String nameParam");
		query.setUnique(true);

		try {
			tag = (Tag) query.execute(name);
		}
		finally {
			query.closeAll();
			persistenceManager.close();
		}

		return tag;
	}

}
